package org.jadapter.tests;

import static org.junit.Assert.assertEquals;

import org.jadapter.JAdapter;
import org.jadapter.examples.foobar.Bar;
import org.jadapter.examples.foobar.BarCsv;
import org.jadapter.examples.foobar.Foo;
import org.jadapter.examples.foobar.FooBar;
import org.jadapter.examples.foobar.FooBean;
import org.jadapter.registry.TransitiveAdapterRegistry;
import org.jadapter.tests.examples.Csv;
import org.jadapter.weavers.RegistryWeaver;
import org.jadapter.weavers.Weaver;
import org.junit.Test;


public class TestWeaver {
    
	
    @Test
	public void shouldProxyAllImplementors() {

        TransitiveAdapterRegistry registry = new TransitiveAdapterRegistry(
                new JAdapter(FooBar.class),
                new JAdapter(BarCsv.class)
        );

        Weaver weaver = new RegistryWeaver(registry);                 
        
        Foo foo = new FooBean(2);
     
        foo = weaver.weave(foo);
        
        assertEquals(2, foo.foo());
        
        Bar bar = (Bar) foo;
        assertEquals(3, bar.bar());
        
        Csv csv = (Csv)foo;
        assertEquals("3", csv.csv());         
        
    }
    
   
    

}
